<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends Pre_Controller
{
    public function __construct()
    {
        parent::__construct();
    }


    //订单编号
    function get_order_sn()
    {
        /* 选择一个随机的方案 */
        mt_srand((double) microtime() * 1000000);

        return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
    }

    public function index()
    {
       

        //$this->output->cache(5);
        $this->load->Model('Website_model');
        $data['up_first_website_model']=$this->Website_model->get_website_by_type_weight(0,1);
        $data['up_second_website_model']=$this->Website_model->get_website_by_type_weight(0,2);
        $data['up_third_website_model']=$this->Website_model->get_website_by_type_weight(0,3);

        $data['down_first_website_model']=$this->Website_model->get_website_by_type_weight(1,1);
        $data['down_second_website_model']=$this->Website_model->get_website_by_type_weight(1,2);
        $data['down_third_website_model']=$this->Website_model->get_website_by_type_weight(1,3);
        $data['down_four_website_model']=$this->Website_model->get_website_by_type_weight(1,4);

        $this->load->Model('Banner_model');
        $banner_list=$this->Banner_model->get_all_banner();
        $data['banner_list']=$banner_list;


        $myfile = fopen("newfile.txt", "a+") or die("Unable to open file!");
        $txt = "Bill Gates\n";
        fwrite($myfile, $txt);
        $txt = "Steve Jobs\n";
        fwrite($myfile, $txt);
        fclose($myfile);
        // p('121231233');


        $this->load->view('Pre/index.html',$data);
        //$string = $this->output->get_output();
        //echo($string);
    }

    public function create_static_html()
    {
        //$url=site_url();
        //$html = file_get_contents($url);


    }

    public function send_mail()
    {
        //$this->load->library('mailer');
        $this->load->library('Mailer');
        $mail=$this->mailer;
        $mail->from='lxb932979339@163.com';
        $mail->from_name='lxb93293212379339';
        $mail->address='1812717753@qq.com';
        $mail->address_name='1812717753';
        $mail->body='给你发送第一个邮件';
        $mail->subject='测试';
        $mail->ishtml=true;
        $mail->altbody='';
        $mail->addAttachment='honelsaksjdf';
        p($mail->send());
    }

    public function wxpay()
    {
       // $this->config->load('wxpay_config',TRUE);
       //// $one= $this->load->config('wxpay_config');
       // //$this->config->set_item('partner','2088521344460948','alipay');
       // //$this->config->set_item('seller_id','2088521344460948','alipay');
       // //$this->config->set_item('notify_url',site_url('order/respond'),'alipay');
       // //$this->config->set_item('return_url',site_url('order/success'),'alipay');
       // //$this->config->set_item('key','f9ervk5j2eohgxurcj2dw2q28xxjcnmw','alipay');
       // $config= $this->config->item('wxpay_config');
       // p($config);
        $this->load->library('Wxpay/lib/WxPayApi');
        //$one=new WxPayApi();
        //p(WxPayApi::get_config('APPID'));
        $this->load->view('Pre/wxpay/index.html');
    }

    public function ewm()
    {
        $this->load->library('Wxpay/_log');
        $this->load->view('Pre/wxpay/ewm.html');
        $this->qrcode();
    }

    /**
     * 获取支付二维码图片
     * @return void
     */
    public function qrcode()
    {
        $this->load->library('Wxpay/create_qrcode');
        return create_qrcode::get_qrcode($_GET["data"]);
    }

    public function orderquery()
    {
        ini_set('date.timezone','Asia/Shanghai');
        error_reporting(E_ERROR);
        $this->load->library('Wxpay/lib/WxPayApi');
        $this->load->library('Wxpay/_log');
        $logHandler= new CLogFileHandler("./logs/".date('Y-m-d').'.log');
        $log = _Log::Init($logHandler, 15);
        p($log);
        if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
            $out_trade_no = $_REQUEST["out_trade_no"];
            $input = new WxPayOrderQuery();
            $input->SetOut_trade_no($out_trade_no);
            p(WxPayApi::orderQuery($input));
            return WxPayApi::orderQuery($input);
        }
        return null;
    }
}
